<?php
namespace V3;
use Util\Config;

class C_TabStatus extends \ResourceClass
{
    public $isActive = true;
    public $remark = '个人';

    public function get(array $req, array $post, &$result)
    {
        if (!isset($req['uid'])) {
            return 'require user uid';
        }
        if (!isset($req['userType'])) {
            return 'require user type';
        }
        if (!isset($req['k']) || !isset($req['t'])) {
            return 'data error';
        }
        $user_cls = \Biz\UserHandler::getById($req['userType'], $req['uid']);
        $enterprise_id = $user_cls->getEnterpriseId();
        /* 授权验证*/
        if (\Biz\UserHandler::checkAuth($req['userType'], $req['uid'], $enterprise_id, $req['id'] . $req['t'] , $req['k']) == false) {
            return 'data illegal';
        }
        $isvalid = 0;
        if (!isset($req['tab'])) {
            $isvalid = 0;
        }
        if (!isset($req['ts'])) {
            $isvalid = 0;
        }
        if(($req['tab']=='home'|| $req['tab']=='market' || $req['tab']=='cart' || $req['tab']=='user') && (time()-$req['ts'])<60 ){
            $isvalid = 1;
        }

        //版本升级逻辑处理
        $need_update = 0;//版本无需更新
        $update_url = '';
        $current_version = Config::get('APP_VERSION','Version');//当前安卓版本最新版本号

        if(isset($req['app_v']) && !empty($req['app_v'])){
            if($req['app_v'] < $current_version){
                $need_update = 1;
                $update_url ='http://download.freshqiao.com/android/xianqiao_'.$current_version.'.apk';
            }
        }

        $mine_status = 0;
        $new_message = 0;
        $new_version = 0;
        $new_status = 0;
        //
        $user_handler = new \Biz\CustomerFeedbackHandler();
        $new_feedback = $user_handler->getFeedbackStatusByUid($req['uid']);

        if ($new_feedback == 1 || $new_message == 1 || $new_version == 1 || $new_status == 1) {
            $mine_status = 1;
        }
        $tab = isset($req['tab']) ? $req['tab'] : '';
        $result = array(
            'mine_status' => $mine_status,
            'index_status' => 0,
            'shop_status' => 0,
            'order_status' => 0,
            'isvalid' =>$isvalid,
            'tab'=>$tab,
            'need_update'=>$need_update,
            'update_url' =>$update_url
        );
    }
}